﻿<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"/>
<title>Web剪刀手</title>
<link rel="stylesheet" type="text/css" href="http://webscissor.appspot.com/static/options.css"/>
<link rel="shortcut icon" href="http://webscissor.appspot.com/static/logo_32.png" type="image/x-icon" /> 
<style type='text/css'>

</style>
<script type="text/javascript" src="http://webscissor.appspot.com/static/jquery-1.4.js"></script>
<script type="text/javascript" src="http://webscissor.appspot.com/static/YX_Base.js"></script>
<script> 
var currentpage = 0;
var PAGE_SIZE=7;
var yxBase = new YXBase("http://webscissor.appspot.com",3);
var yxBase2 = new YXBase("http://webscissor.appspot.com",2);

function getid(element) {
  if (typeof element == 'string')
   return document.getElementById(element);
}

//从本地加载文件
function LoadLocalPage(localFile,funSuccess,funError)
{
    $.ajax({
      url:localFile,
      type: 'GET',
      success: function(data) {
         funSuccess(data);
      },
      error: function(XMLHttpRequest, textStatus, errorThrown){
         funError(textStatus);
      }
    });
}

function UploadFirst()
{
    yxBase2.AddData(data,function (res){
            alert("更新成功，版本号为" + res[1]);
        },
        function (error){
            alert("更新失败，error=" + error);
        }
    );
}
function Upload()
{
    LoadLocalPage('/item.htm',function (data){
        yxBase2.UpdateData(
            10001,data,function (res){
                alert("更新成功，版本号为" + res[1]);
                }
            )
        },
        function (error){
            UploadFirst();
        }
    );
}

//把本地index.htm上传到服务器gid=0的地址上
function UpdateIndexPage()
{
    yxBase2.GetUserID(function(user){
        yxBase2.GetNGVER(function(res){
            Upload();
        });
    });
}
 
//从URL里提取用户ID和item ID。
//URL 格式：http://webscissor.appspot.com/use_id/gid/
function GetUrlGID(strRet)
{
    //return /code=(\d*)/.exec(strRet)[1];
    var res = /http:\/\/webscissor.appspot.com\/(\d*)\/(\d*)\//.exec(strRet);
    return {user_id:res[1],gid:res[2]};
}
//alert(GetUrlGID("http://webscissor.appspot.com/123/456/").gid);

function ShowData()
{
    yxBase.GetData(10001,function (res){
        var gid  = res[0];
        var gver = res[1];
        var del  = res[2];
        var item = JSON.parse(res[3]);
        var title = item[1];
        var body = item[2];
        var pageUrl = item[3];
        var addTime = new Date(item[4]);
        getid("div_data").innerHTML += "<H1>" + title + "</H1><pre>" + body + "</pre>";
        window.document.title = title + "Web剪刀手";
    });
}

$(document).ready(function(){
	yxBase.GetUserID(
		function (){
			getid("span_username").innerHTML = yxBase.user_mail
				+' | <a href="http://webscissor.appspot.com/Logout?redi_url=/' 
				+ '">退出</a>';
            //ShowData();
            //UpdateIndexPage();
		},
		function(){
			getid("span_username").innerHTML = '<a href="http://webscissor.appspot.com/Login?redi_url=/' 
				+ '">登录</a>';
			//getid("span_update_status").innerHTML = '请登录后开始同步';
		}
	);
});
</script>
</head>
<body>
	<div id="debug"></div>
    <div id="main_container">
        <table width="90%" valign="top" align="center">
            <tr>
                <td align="left">
					<h1><img src="http://webscissor.appspot.com/static/logo_32.png" width="30" />Web剪刀手</h1>
                </td>
                <td align="right">
                    <p>
                        <a href="./remember.htm">首页</a> | 
						<a href="./export.htm">导出</a> | 
						<a href="./import.htm">导入</a> | 
						<a href="http://code.google.com/p/webclip/" >Web剪刀手</a> |
                        <span id="span_username"><a href="http://webscissor.appspot.com/Login?redi_url=remember.htm" target="_blank">登录</a></span> 
                        
                    </p>
                </td>
            </tr>
        </table>
<table cellpadding="5" class="settings-table">
	<tr>
		<td valign="top" width="75%">
			<table width="100%">
				<tr>
					<td>
					</td>
					<td align="left">
        <input type="button" value="Upload item.htm" onclick="UpdateIndexPage()"></input>
						<div id="div_data"></div>
					</td>
					<td align="right">
					</td>
				</tr>
			</table>
			<div id="div_words">
			</div>
		</td>
		<!-- <td valign="top" width="15%">
			<div id="div_tags">
			</div> 
		</td>-->
	</tr>
</table>

</body>
</html>